-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve CLI, refactor and document stubgen #6256
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really makes stubgen a much more useful tool! Additional thanks for cleaning up the code and writing docstrings.
This the first part of my review. I'll continue next week.
Some general things:
- Some generated aliases may define a name with an underscore prefix (e.g. if I generate a stub for
os
). Should these be filtered out? - Similar to above, some aliases use names with an underscore prefix (e.g. if I generate stub for
os
). Should these be declared asx: Any
instead? - Some generated constants are declared as
x: Final
. Should these bex: Final[Any]
instead?
@JukkaL Thanks for review! I implemented your comments. Regarding private names: it is now controlled by A general comment, I didn't strive for completeness in this PR, small fixes (like above) can be added to this PR, but for all larger things I would rather open follow-up issues. |
(AppVeyor failure is a flake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updates! This concludes my review; left a bunch of mostly minor nits. Feel free to ignore things that aren't relevant and create follow-up issues for things that are non-trivial to address.
OK, playing with real stub generation discovered an issue: we should not add |
docs/source/stubgen.rst
Outdated
Don't try to import modules, instead use mypy's normal mechanisms to find | ||
sources. This will not find any C extension modules. Stubgen also uses | ||
runtime introspection to find actual value of ``__all__``, so with this flag | ||
the set of re-expoted names may be incomplete. This flag will be useful if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expoted
docs/source/stubgen.rst
Outdated
|
||
``--parse-only`` | ||
Don't perform mypy semantic analysis of source files. This may generate | ||
worse stubs, in particular some module, class, and function aliases may |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first comma should be a colon
The changes in response to my review look good. |
test-data/unit/stubgen.test
Outdated
|
||
class A(metaclass=ABCMeta): | ||
@abstractmethod | ||
def meth(self) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the return type be Any
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return is Any
only if we run semantic analyzer (test name should end in _semanal
), see a test below. But on the second thought it looks like it is not always necessary, in most common cases (like when we add the decorator here) it is better to return Any
. I will fix this now.
test-data/unit/stubgen.test
Outdated
|
||
class A(metaclass=abc.ABCMeta): | ||
@abc.abstractmethod | ||
def meth(self) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, should the return type be Any
?
Also use tighter formatting in tests.
Oh, GitHub somehow completely screwed up my merge. I will try to fix it. |
OK, it was actually my fault, I didn't add one file to the commit :P |
Unless there are some objections, I am going to merge this soon after tests pass. |
This PR does several "infrastructure" changes to
stubgen
tool:mypy
CLIstubgen.main()
into independent functionsstubdoc.py
stubgen.py
tostubutil.py
and reorganize the latterDataSuite
stubgen
scriptThis also does few smaller things:
stubgenc.py
and (new)stubdoc.py
This is not a pure refactoring, turning the semantic analysis on required some (although relatively small) changes in logic (because the sources should be semantically analyzed as a whole). It also required couple minor changes in
semanal.py
andbuild.py
.